<!-- Imports -->
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Hashtable"%>
<%@page import="canss.supports.basic"%>
<%@page import="canss.supports.Makequery_select"%>
<!-- Component start -->
<%{ %>
<!-- Initiation -->
<%
	response.setContentType("text/html; charset=UTF-8");
	canss.web.controls.WebDBControl webdbcontrol = null;
	webdbcontrol = (webdbcontrol == null) ? new canss.web.controls.WebDBControlBean() : webdbcontrol;
%>
<!-- Preparing inputs -->
<%
	int i = 0;
%>
<!-- Query Compilation -->
<%
	Makequery_select query = new Makequery_select()
	.Select("count(*) as count, floor(canssperson_type/10) as persontype")
	.PushFrom("tblPerson")
	.GroupBy("floor(canssperson_type/10)")
	.PushWhere("floor(canssperson_type/10)>1");
	String[] persontypeenum = {"", "Admin","End User","Content Provider","3rd Party"};

	Iterator<String[]> iter = null;
	Hashtable<String, Integer> hash = null;
	try
	{
		LinkedList<String[]> res = webdbcontrol.Select(query);
		iter = res.iterator();
		if (iter.hasNext())
		{
	String[] curhashtmp = iter.next();
	hash = new Hashtable<String, Integer>(curhashtmp.length);
	for (i = 0; i < curhashtmp.length; i++)
		hash.put(curhashtmp[i], i);
		}
	} catch (Exception e)
	{
		e.printStackTrace();
	}
%>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
		// Load the Visualization API and the piechart package.
		google.load('visualization', '1', {'packages':['piechart']});
		// Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChartMember_div);
    function drawChartMember_div()
    {
			var persondata = new google.visualization.DataTable();
			persondata.addColumn('string', 'Status');
			persondata.addColumn('number', 'Counts');
			<%
				out.write("persondata.addRows([");
				boolean isfirstiter = true;
				while(iter!=null && iter.hasNext())
				{
					String[] cur = iter.next();
					if(isfirstiter)
					{
						isfirstiter = false;
					}else
						out.write(",\n");
					out.write(String.format(" ['%s', %s]", persontypeenum[Integer.valueOf(cur[hash.get("persontype")])], cur[hash.get("count")]));
				}
				out.write("]);");
			%>
			var memberdivchart = new google.visualization.PieChart(document.getElementById('Member_div'));
			memberdivchart.draw(persondata, {width: 480, height: 300, is3D: true, title: 'Member Registration Status'});
		}
	</script>

<div id="Member_div"></div>
<%} %>
<!-- Component end -->